#if !defined(AFX_DLGMODELPARAM_H__BDC0BA58_FDEF_4B3F_92E6_5898F56034B6__INCLUDED_)
#define AFX_DLGMODELPARAM_H__BDC0BA58_FDEF_4B3F_92E6_5898F56034B6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgModelParam.h : header file
//

#include "DlgSupport.h"
#include "PartGenerator.h"
#include "BitmapPicture.h"

/////////////////////////////////////////////////////////////////////////////
// CDlgModelParam dialog
class Part;

class DllExport PartChooseManager : public ManagerTemplate<CString, Part>
{
public:
	PartChooseManager(){
	}
	virtual ~PartChooseManager(){
	}

public:
	Part* GetChoosePart(const CString& strPartID, const CString& strStandard){
		ASSERT(!strPartID.IsEmpty());
		ASSERT(!strStandard.IsEmpty());

		CString strKey = strPartID + strStandard;
		Part* pPart = GetManaged(strKey);
		if(pPart != NULL)
			return pPart;

		pPart = GetPartGenerator().Generate(strPartID, strStandard);
		ASSERT(pPart);
		Add(strKey, pPart);
		return pPart;
	}

	void AddPart(Part* pPart){
		ASSERT(pPart);
		ASSERT(!pPart->GetCustomID().IsEmpty());
		ASSERT(!pPart->GetStandard().IsEmpty());

		CString strKey = pPart->GetCustomID() + pPart->GetStandard();
		Add(strKey, pPart);
	}

};

#define WM_UPDATEPICTURE WM_USER+1

class DllExport CDlgModelParam : public CDialog
{
// Construction
public:
	enum ParamType{
		ePART,
			eATTACH};
	CDlgModelParam(ParamType eType = ePART, CWnd* pParent = NULL);   // standard constructor
	CDlgModelParam(Part* pPart, BOOL bEdit = FALSE, ParamType eType = ePART, CWnd* pParent = NULL);
// Dialog Data
	//{{AFX_DATA(CDlgModelParam)
	enum { IDD = IDD_MODELPARAM_DIALOG };
	BitmapPicture	m_Picture;
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDlgModelParam)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

public:
	Part* GetPart();
	

private:
	void InitPartStyleCombo();
	INT GetStyleNum(const CString& strName);
	void SetPartStandardCombo(INT nStyle);
	void SetPartCombo(const CString& strStandard);
	void UpdateParamView(const CString& strPartID, const CString& strStandard);
	void GetParamViewRect();
	void ShowPartPicture(Part* pPart);
	
private:
	CStringArray m_strStyleName;
	ModelParamVisitorManager m_theVisitorManager;
	PartChooseManager m_thePartManager;
	CRect m_ParamViewRect;

	Part* m_pPart;
	ModelParamVisitor* m_pVisitor;
	BOOL m_bIsInit;
	BOOL m_bEdit;
// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CDlgModelParam)
	afx_msg void OnSelchangePartstandardCombo();
	afx_msg void OnSelchangePartstyleCombo();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	virtual BOOL OnInitDialog();
	afx_msg void OnSelchangePartCombo();
	afx_msg LRESULT OnUpdatePicture(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnPartAvialable(WPARAM wParam, LPARAM lParam);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLGMODELPARAM_H__BDC0BA58_FDEF_4B3F_92E6_5898F56034B6__INCLUDED_)
